<template>
  <div class="el_main_con">
    <Breadcrumb></Breadcrumb>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input placeholder="请输入搜索商品" v-model="orderParams.query" clearable @clear="getOrderList()">
            <el-button slot="append" icon="el-icon-search" @click="getOrderList()"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="user_id" label="用户 ID" :width="80"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单金额" :width="150"></el-table-column>
        <el-table-column label="支付状态" :width="80">
          <template slot-scope="scope">
            <div>
              <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
              <el-tag type="warning" v-else-if="scope.row.pay_status === '0'">未付款</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" :width="150">
          <template slot-scope="scope">
            {{scope.row.create_time | dft}}
          </template>
        </el-table-column>
        <el-table-column label="订单支付" :width="80">
          <template slot-scope="scope">
            <div>
              <el-tag type="warning" v-if="scope.row.order_pay === '0'">未支付</el-tag>
              <el-tag type="success" v-if="scope.row.order_pay === '1'">支付宝</el-tag>
              <el-tag type="success" v-if="scope.row.order_pay === '2'">微信</el-tag>
              <el-tag type="success" v-if="scope.row.order_pay === '3'">银行卡</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" :width="100">
          <template>
            <div>
              <el-button type="primary" icon="el-icon-edit" circle size="mini" @click="showdialogAddressVisible"></el-button>
              <el-button type="success" icon="el-icon-location-outline" circle size="mini" @click="showdialogWuliuVisible"></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="paginationBox">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="orderParams.pagenum" :page-sizes="[10,20,50,100]" :page-size="orderParams.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
    </el-card>
    <el-dialog title="修改地址" :visible.sync="dialogAddressVisible" width="30%">
      <el-form :model="addressForm" :rules="addressFormRules" ref="addressForm" label-width="100px">
        <el-form-item label="省市区/县" prop="address1">
          <el-input v-model="addressForm.address1"></el-input>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogAddressVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogAddressVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="物流信息" :visible.sync="dialogWuliuVisible" width="30%">
      <el-timeline>
        <el-timeline-item v-for="(activity, index) in activities" :key="index" :icon="activity.icon" :type="activity.type" :color="activity.color" :size="activity.size" :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogWuliuVisible = false">关 闭</el-button>
        <el-button type="primary" @click="dialogWuliuVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { Goods } from '@/api/apiConfig'
import Breadcrumb from 'components/breadcrumb/breadcrumb'
export default {
  components: {
    Breadcrumb
  },
  data () {
    return {
      orderList: [],
      orderParams: {
        query: '',
        pagenum: 1,
        pagesize: 10,
        user_id: '',
        ID: '',
        pay_status: '',
        is_send: '',
        order_fapiao_title: '',
        order_fapiao_company: '',
        order_fapiao_content: '',
        consignee_addr: ''
      },
      total: 0,
      dialogAddressVisible: false,
      addressForm: {
        address1: '',
        address2: ''
      },
      addressFormRules: {
        address1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      dialogWuliuVisible: false,
      activities: [{
        content: '支持使用图标',
        timestamp: '2018-04-12 20:46',
        size: 'large',
        type: 'primary',
        icon: 'el-icon-more'
      }, {
        content: '支持自定义颜色',
        timestamp: '2018-04-03 20:46',
        color: '#0bbd87'
      }, {
        content: '支持自定义尺寸',
        timestamp: '2018-04-03 20:46',
        size: 'large'
      }, {
        content: '默认样式的节点',
        timestamp: '2018-04-03 20:46'
      }]
    }
  },
  mounted () {
    this.getOrderList()
  },
  methods: {
    getOrderList () {
      Goods.getOrderList(this.orderParams).then(res => {
        if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
        this.$message.success(res.meta.msg)
        this.orderList = res.data.goods
        this.total = res.data.total
      })
    },
    handleSizeChange (newSize) {
      this.orderParams.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange (newPage) {
      this.orderParams.pagenum = newPage
      this.getOrderList()
    },
    showdialogAddressVisible () {
      this.dialogAddressVisible = true
    },
    async showdialogWuliuVisible () {
      await this.getCheckWuliu()
      this.dialogWuliuVisible = true
    },
    getCheckWuliu () {
      const url = 'kuaidi/1106975712662'
      Goods.checkWuliu(url).then(res => {
        this.activities = res.data
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
